{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b934c710-e5bb-4525-9a25-46b8eb1087ac",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-09T05:41:23.630708Z",
     "iopub.status.busy": "2024-09-09T05:41:23.630367Z",
     "iopub.status.idle": "2024-09-09T05:41:28.754266Z",
     "shell.execute_reply": "2024-09-09T05:41:28.753494Z",
     "shell.execute_reply.started": "2024-09-09T05:41:23.630688Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正克隆到 'LLaMA-Factory'...\n",
      "remote: Enumerating objects: 315, done.\u001b[K\n",
      "remote: Counting objects: 100% (315/315), done.\u001b[K\n",
      "remote: Compressing objects: 100% (245/245), done.\u001b[K\n",
      "remote: Total 315 (delta 80), reused 192 (delta 57), pack-reused 0 (from 0)\u001b[K\n",
      "接收对象中: 100% (315/315), 8.94 MiB | 2.86 MiB/s, 完成.\n",
      "处理 delta 中: 100% (80/80), 完成.\n"
     ]
    }
   ],
   "source": [
    "!git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "72111ae9-0faf-404b-b1c4-163d2370ea3e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-09T05:41:35.326362Z",
     "iopub.status.busy": "2024-09-09T05:41:35.325998Z",
     "iopub.status.idle": "2024-09-09T05:41:35.330386Z",
     "shell.execute_reply": "2024-09-09T05:41:35.329900Z",
     "shell.execute_reply.started": "2024-09-09T05:41:35.326342Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/mnt/workspace/LLaMA-Factory\n"
     ]
    }
   ],
   "source": [
    "%cd LLaMA-Factory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6b76334f-82b3-4e3f-8e2a-3099143913be",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-09T05:41:36.924624Z",
     "iopub.status.busy": "2024-09-09T05:41:36.924261Z",
     "iopub.status.idle": "2024-09-09T05:41:50.810026Z",
     "shell.execute_reply": "2024-09-09T05:41:50.809451Z",
     "shell.execute_reply.started": "2024-09-09T05:41:36.924597Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.cloud.aliyuncs.com/pypi/simple\n",
      "Obtaining file:///mnt/workspace/LLaMA-Factory\n",
      "  Installing build dependencies ... \u001b[?25ldone\n",
      "\u001b[?25h  Checking if build backend supports build_editable ... \u001b[?25ldone\n",
      "\u001b[?25h  Getting requirements to build editable ... \u001b[?25ldone\n",
      "\u001b[?25h  Preparing editable metadata (pyproject.toml) ... \u001b[?25ldone\n",
      "\u001b[?25hRequirement already satisfied: einops in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.8.0)\n",
      "Requirement already satisfied: packaging in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (24.0)\n",
      "Requirement already satisfied: pandas>=2.0.0 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (2.2.2)\n",
      "Collecting gradio>=4.0.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/70/cd/b5a61e6c5fba0daad1b76dae9ebd0cc6e127be1cc20e19175ba6de2c9c3a/gradio-4.43.0-py3-none-any.whl (18.1 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.1/18.1 MB\u001b[0m \u001b[31m93.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: matplotlib>=3.7.0 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (3.9.0)\n",
      "Requirement already satisfied: scipy in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (1.12.0)\n",
      "Requirement already satisfied: datasets<=2.21.0,>=2.16.0 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (2.18.0)\n",
      "Requirement already satisfied: transformers<=4.45.0,>=4.41.2 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (4.42.4)\n",
      "Requirement already satisfied: protobuf in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (3.20.3)\n",
      "Requirement already satisfied: pydantic in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (2.7.4)\n",
      "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (6.0.1)\n",
      "Requirement already satisfied: numpy<2.0.0 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (1.26.3)\n",
      "Requirement already satisfied: accelerate<=0.33.0,>=0.30.1 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.33.0)\n",
      "Requirement already satisfied: tiktoken in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.7.0)\n",
      "Requirement already satisfied: sse-starlette in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (2.1.2)\n",
      "Requirement already satisfied: peft<=0.12.0,>=0.11.1 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.11.1)\n",
      "Requirement already satisfied: fire in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.6.0)\n",
      "Requirement already satisfied: fastapi in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.111.1)\n",
      "Requirement already satisfied: uvicorn in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.30.3)\n",
      "Requirement already satisfied: trl<=0.9.6,>=0.8.6 in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.9.6)\n",
      "Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.2.0)\n",
      "Requirement already satisfied: jieba in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (0.42.1)\n",
      "Requirement already satisfied: nltk in /usr/local/lib/python3.10/site-packages (from llamafactory==0.9.0) (3.8.1)\n",
      "Collecting rouge-chinese\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/03/0f/394cf877be7b903881020ef7217f7dc644dad158d52a9353fcab22e3464d/rouge_chinese-1.0.3-py3-none-any.whl (21 kB)\n",
      "Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.10/site-packages (from accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (2.3.1)\n",
      "Requirement already satisfied: psutil in /usr/local/lib/python3.10/site-packages (from accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (5.9.8)\n",
      "Requirement already satisfied: huggingface-hub>=0.21.0 in /usr/local/lib/python3.10/site-packages (from accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (0.23.5)\n",
      "Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/site-packages (from accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (0.4.3)\n",
      "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (3.9.5)\n",
      "Requirement already satisfied: pyarrow>=12.0.0 in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (17.0.0)\n",
      "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (2.32.3)\n",
      "Requirement already satisfied: tqdm>=4.62.1 in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (4.66.4)\n",
      "Requirement already satisfied: filelock in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (3.14.0)\n",
      "Requirement already satisfied: fsspec[http]<=2024.2.0,>=2023.1.0 in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (2024.2.0)\n",
      "Requirement already satisfied: multiprocess in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (0.70.16)\n",
      "Requirement already satisfied: pyarrow-hotfix in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (0.6)\n",
      "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (0.3.8)\n",
      "Requirement already satisfied: xxhash in /usr/local/lib/python3.10/site-packages (from datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (3.4.1)\n",
      "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (10.2.0)\n",
      "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (3.1.4)\n",
      "Collecting gradio-client==1.3.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/de/fe/7e9cb4d0e6aa74268fa31089189e4855882a0f2a36c45d359336946d4ae1/gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.7/318.7 kB\u001b[0m \u001b[31m80.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (2.1.5)\n",
      "Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (0.27.0)\n",
      "Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (0.12.3)\n",
      "Collecting ffmpy\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/ff/1e/db99aa669eee301966bc6c997d60a0240f9cecae63f044b2e5a5310e4bf7/ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n",
      "Collecting importlib-resources<7.0,>=1.3\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/db/2a/728c8ae66011600fac5731a7db030d23c42f1321fd9547654f0c3b2b32d7/importlib_resources-6.4.4-py3-none-any.whl (35 kB)\n",
      "Collecting semantic-version~=2.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/6a/23/8146aad7d88f4fcb3a6218f41a60f6c2d4e3a72de72da1825dc7c8f7877c/semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
      "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (2.2.1)\n",
      "Collecting aiofiles<24.0,>=22.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/c5/19/5af6804c4cc0fed83f47bff6e413a98a36618e7d40185cd36e69737f3b0e/aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
      "Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (4.4.0)\n",
      "Collecting pydub\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/a6/53/d78dc063216e62fc55f6b2eebb447f6a4b0a59f55c8406376f76bf959b08/pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
      "Requirement already satisfied: python-multipart>=0.0.9 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (0.0.9)\n",
      "Collecting tomlkit==0.12.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/68/4f/12207897848a653d03ebbf6775a29d949408ded5f99b2d87198bc5c93508/tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
      "Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/site-packages (from gradio>=4.0.0->llamafactory==0.9.0) (4.12.0)\n",
      "Collecting ruff>=0.2.2\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/c5/70/899b03cbb3eb48ed0507d4b32b6f7aee562bc618ef9ffda855ec98c0461a/ruff-0.6.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.3 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.3/10.3 MB\u001b[0m \u001b[31m129.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hCollecting orjson~=3.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/b6/bc/fbd345d771a73cacc5b0e774d034cd081590b336754c511f4ead9fdc4cf1/orjson-3.10.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m55.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: websockets<13.0,>=10.0 in /usr/local/lib/python3.10/site-packages (from gradio-client==1.3.0->gradio>=4.0.0->llamafactory==0.9.0) (12.0)\n",
      "Requirement already satisfied: email_validator>=2.0.0 in /usr/local/lib/python3.10/site-packages (from fastapi->llamafactory==0.9.0) (2.2.0)\n",
      "Requirement already satisfied: fastapi-cli>=0.0.2 in /usr/local/lib/python3.10/site-packages (from fastapi->llamafactory==0.9.0) (0.0.4)\n",
      "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /usr/local/lib/python3.10/site-packages (from fastapi->llamafactory==0.9.0) (0.37.2)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (4.53.0)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (1.2.1)\n",
      "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (0.12.1)\n",
      "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (1.4.5)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (3.1.2)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/site-packages (from matplotlib>=3.7.0->llamafactory==0.9.0) (2.9.0.post0)\n",
      "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/site-packages (from pandas>=2.0.0->llamafactory==0.9.0) (2024.1)\n",
      "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/site-packages (from pandas>=2.0.0->llamafactory==0.9.0) (2024.1)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/site-packages (from pydantic->llamafactory==0.9.0) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/site-packages (from pydantic->llamafactory==0.9.0) (2.18.4)\n",
      "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/site-packages (from transformers<=4.45.0,>=4.41.2->llamafactory==0.9.0) (2024.5.15)\n",
      "Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/site-packages (from transformers<=4.45.0,>=4.41.2->llamafactory==0.9.0) (0.19.1)\n",
      "Requirement already satisfied: tyro>=0.5.11 in /usr/local/lib/python3.10/site-packages (from trl<=0.9.6,>=0.8.6->llamafactory==0.9.0) (0.8.5)\n",
      "Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (0.14.0)\n",
      "Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (8.1.7)\n",
      "Requirement already satisfied: termcolor in /usr/local/lib/python3.10/site-packages (from fire->llamafactory==0.9.0) (2.4.0)\n",
      "Requirement already satisfied: six in /usr/local/lib/python3.10/site-packages (from fire->llamafactory==0.9.0) (1.16.0)\n",
      "Requirement already satisfied: joblib in /usr/local/lib/python3.10/site-packages (from nltk->llamafactory==0.9.0) (1.4.2)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio>=4.0.0->llamafactory==0.9.0) (1.2.1)\n",
      "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio>=4.0.0->llamafactory==0.9.0) (3.7)\n",
      "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio>=4.0.0->llamafactory==0.9.0) (1.3.1)\n",
      "Requirement already satisfied: dnspython>=2.0.0 in /usr/local/lib/python3.10/site-packages (from email_validator>=2.0.0->fastapi->llamafactory==0.9.0) (2.3.0)\n",
      "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (4.0.3)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (23.2.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (1.9.4)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (1.3.1)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (6.0.5)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/site-packages (from aiohttp->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (1.4.1)\n",
      "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/site-packages (from httpx>=0.24.1->gradio>=4.0.0->llamafactory==0.9.0) (1.0.5)\n",
      "Requirement already satisfied: certifi in /usr/local/lib/python3.10/site-packages (from httpx>=0.24.1->gradio>=4.0.0->llamafactory==0.9.0) (2024.2.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/site-packages (from requests>=2.19.0->datasets<=2.21.0,>=2.16.0->llamafactory==0.9.0) (3.3.2)\n",
      "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.3.1)\n",
      "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.0.106)\n",
      "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.105)\n",
      "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.105)\n",
      "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (11.0.2.54)\n",
      "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (10.3.2.106)\n",
      "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.105)\n",
      "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (11.4.5.107)\n",
      "Requirement already satisfied: triton==2.3.1 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (2.3.1)\n",
      "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.1.105)\n",
      "Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (2.20.5)\n",
      "Requirement already satisfied: networkx in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (3.3)\n",
      "Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (8.9.2.26)\n",
      "Requirement already satisfied: sympy in /usr/local/lib/python3.10/site-packages (from torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (1.12.1)\n",
      "Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (12.5.82)\n",
      "Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio>=4.0.0->llamafactory==0.9.0) (1.5.4)\n",
      "Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio>=4.0.0->llamafactory==0.9.0) (13.7.1)\n",
      "Requirement already satisfied: docstring-parser>=0.16 in /usr/local/lib/python3.10/site-packages (from tyro>=0.5.11->trl<=0.9.6,>=0.8.6->llamafactory==0.9.0) (0.16)\n",
      "Requirement already satisfied: shtab>=1.5.6 in /usr/local/lib/python3.10/site-packages (from tyro>=0.5.11->trl<=0.9.6,>=0.8.6->llamafactory==0.9.0) (1.7.1)\n",
      "Requirement already satisfied: httptools>=0.5.0 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (0.6.1)\n",
      "Requirement already satisfied: watchfiles>=0.13 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (0.22.0)\n",
      "Requirement already satisfied: python-dotenv>=0.13 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (1.0.1)\n",
      "Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /usr/local/lib/python3.10/site-packages (from uvicorn->llamafactory==0.9.0) (0.19.0)\n",
      "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio>=4.0.0->llamafactory==0.9.0) (2.18.0)\n",
      "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio>=4.0.0->llamafactory==0.9.0) (3.0.0)\n",
      "Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /usr/local/lib/python3.10/site-packages (from sympy->torch>=1.10.0->accelerate<=0.33.0,>=0.30.1->llamafactory==0.9.0) (1.3.0)\n",
      "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio>=4.0.0->llamafactory==0.9.0) (0.1.2)\n",
      "Building wheels for collected packages: llamafactory\n",
      "  Building editable for llamafactory (pyproject.toml) ... \u001b[?25ldone\n",
      "\u001b[?25h  Created wheel for llamafactory: filename=llamafactory-0.9.0-0.editable-py3-none-any.whl size=22293 sha256=da9b3f7ad1329f4cad3798c45b99714a10f1c030a97a073835e659887ff76fe4\n",
      "  Stored in directory: /tmp/pip-ephem-wheel-cache-ysf3k40k/wheels/5c/79/7e/72c80d84fb58351f0f8d2e48a93b05787aabc61467c934c42c\n",
      "Successfully built llamafactory\n",
      "Installing collected packages: pydub, tomlkit, semantic-version, ruff, rouge-chinese, orjson, importlib-resources, ffmpy, aiofiles, gradio-client, gradio, llamafactory\n",
      "Successfully installed aiofiles-23.2.1 ffmpy-0.4.0 gradio-4.43.0 gradio-client-1.3.0 importlib-resources-6.4.4 llamafactory-0.9.0 orjson-3.10.7 pydub-0.25.1 rouge-chinese-1.0.3 ruff-0.6.4 semantic-version-2.10.0 tomlkit-0.12.0\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
      "\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install -e .[metrics]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "707cc6ac-6f8c-4cb2-a8a8-29ea47735962",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-09T05:41:54.946169Z",
     "iopub.status.busy": "2024-09-09T05:41:54.945796Z",
     "iopub.status.idle": "2024-09-09T05:42:30.096962Z",
     "shell.execute_reply": "2024-09-09T05:42:30.096262Z",
     "shell.execute_reply.started": "2024-09-09T05:41:54.946144Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading: 100%|█████████████████████████████| 660/660 [00:00<00:00, 1.22kB/s]\n",
      "Downloading: 100%|████████████████████████████| 48.0/48.0 [00:04<00:00, 10.9B/s]\n",
      "Downloading: 100%|███████████████████████████████| 242/242 [00:00<00:00, 540B/s]\n",
      "Downloading: 100%|█████████████████████████| 11.1k/11.1k [00:00<00:00, 19.7kB/s]\n",
      "Downloading: 100%|█████████████████████████| 1.59M/1.59M [00:00<00:00, 2.59MB/s]\n",
      "Downloading: 100%|██████████████████████████| 2.88G/2.88G [00:15<00:00, 199MB/s]\n",
      "Downloading: 100%|█████████████████████████| 3.47k/3.47k [00:00<00:00, 7.07kB/s]\n",
      "Downloading: 100%|█████████████████████████| 6.70M/6.70M [00:00<00:00, 8.14MB/s]\n",
      "Downloading: 100%|█████████████████████████| 1.26k/1.26k [00:00<00:00, 2.39kB/s]\n",
      "Downloading: 100%|█████████████████████████| 2.65M/2.65M [00:00<00:00, 2.94MB/s]\n"
     ]
    }
   ],
   "source": [
    "!modelscope download --model qwen/Qwen2-1.5B-Instruct --local_dir /mnt/workspace/qwen2-1.5B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a9e4153e-909f-4e4f-b8f3-8db49ddd7b42",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-09T05:45:03.396162Z",
     "iopub.status.busy": "2024-09-09T05:45:03.395818Z",
     "iopub.status.idle": "2024-09-09T05:45:15.459812Z",
     "shell.execute_reply": "2024-09-09T05:45:15.459264Z",
     "shell.execute_reply.started": "2024-09-09T05:45:03.396142Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.10/site-packages/_distutils_hack/__init__.py:55: UserWarning: Reliance on distutils from stdlib is deprecated. Users must rely on setuptools to provide the distutils module. Avoid importing distutils or import setuptools first, and avoid setting SETUPTOOLS_USE_DISTUTILS=stdlib. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml\n",
      "  warnings.warn(\n",
      "[2024-09-09 13:45:09,852] [INFO] [real_accelerator.py:203:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n",
      "df: /root/.triton/autotune: 没有那个文件或目录\n",
      "\u001b[93m [WARNING] \u001b[0m Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH\n",
      "\u001b[93m [WARNING] \u001b[0m sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.3\n",
      "\u001b[93m [WARNING] \u001b[0m using untested triton version (2.3.1), only 1.0.0 is known to be compatible\n",
      "----------------------------------------------------------\n",
      "| Welcome to LLaMA Factory, version 0.9.0                |\n",
      "|                                                        |\n",
      "| Project page: https://github.com/hiyouga/LLaMA-Factory |\n",
      "----------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "!llamafactory-cli version"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
